home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / REALLOC.C < prev    next >
Text File  |  1986-05-18  |  1KB  |  33 lines

  1. /* 1.1  07-10-85                        (realloc.c)
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1984        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10.  
  11. /************************************************************************/
  12.     char *
  13. realloc(ptr, size)    /* Change the size of the block pointed to by ptr,
  14.                to size bytes.  Return pointer to (possibly
  15.                moved) block.  Return NULL if no memory
  16.                available.                    */
  17. /*----------------------------------------------------------------------*/
  18. STRING ptr;
  19. unsigned size;
  20. {
  21.     HEADER *p;
  22.     STRING s, t, malloc();
  23.     int n;
  24.  
  25.     p = (HEADER *) ptr - 1;    /* point to header    */
  26.     n = MIN(p->s.size, size);
  27.     free(ptr);
  28.     if ((s = t = malloc(size)) ISNT NULL AND s ISNT ptr)
  29.         while (n-- > 0)
  30.             *s++ = *ptr++;        /* move the data over.    */
  31.     return s;
  32. }
  33.